var img = [
  'http://image5.tuku.cn/wallpaper/Landscape%20Wallpapers/8294_2560x1600.jpg',
  'http://www.deskcar.com/desktop/fengjing/2011722123730/1.jpg',
  'http://www.33lc.com/article/UploadPic/2012-8/20128181071010672.jpg',
  'http://www.bbra.cn/Uploadfiles/imgs/2016/11/02/tu2/001.jpg',
  'http://www.ctskyril.com/Public/article/2015-05-29/556812ea53938_thumb.jpg',
  'http://www.doudouxitong.net/uploads/allimg/151221/1-15122114433V39.jpg',
  'http://d.5857.com/zirfengg_141208/001.jpg',
  'http://pic1.win4000.com/wallpaper/4/53fee27a01094.jpg',
  'http://pic1.win4000.com/wallpaper/1/56821f8bb1e23.jpg'
];
var imgEle = document.getElementById('img'),
  tip = document.getElementById('tip');

var i = 0,
  len = img.length;

imgEle.src = img[i];
tip.innerHTML = '第' + (i + 1) + '张';

var btn_prop = document.getElementById('btn_prop'),
  btn_next = document.getElementById('btn_next'),
  btn_group = document.getElementById('btn_group'),
  loading = document.getElementById('loading');

var count = 0;
img.forEach(function (src, i) {
  var imgObj = new Image();
  var fn = function () {
    loading.innerHTML = Math.round(count / len * 100) + '%';
    if (count >= len - 1) {
      loading.style.display = 'none';
    }
    count++;
  };
  imgObj.addEventListener(
    'load',
    fn,
    false
  );
  imgObj.addEventListener(
    'error',
    fn,
    false
  );
  imgObj.src = src;
});

btn_group.addEventListener(
  'click',
  function (e) {
    var target = e.target;
    if (target == btn_prop) {
      --i < 0 && (i = len - 1);
    } else {
      ++i > len - 1 && (i = 0);
    }
    imgEle.src = img[i];
    tip.innerHTML = '第' + (i + 1) + '张';
  },
  false
);